﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using LogisticsBLL;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

namespace WebLosgic.Accounting
{
    public partial class CostMaintenance : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindRptList();
                //BindDivDisplay();
                //divNewBlock.Style.Add("display", "none");
            }
        }


        public void BindRptList()
        {
            CostBLL cb = new CostBLL();
            int pageIndex = AspNetPagerTool.CurrentPageIndex;
            int pageSize = AspNetPagerTool.PageSize;
            int Rescout = 0;
            int state = Convert.ToInt32(RblSUMState.SelectedValue);
            string ReceiveDate = TxtChenDate.Text;
            string EndReceDate = Txtchengdata.Text.Trim();
            RptBindDrive.DataSource = cb.CostCarries(pageIndex, pageSize, out Rescout, state, ReceiveDate, EndReceDate);
            AspNetPagerTool.RecordCount = Rescout;
            RptBindDrive.DataBind();
        }

        //protected void RptBindDrive_ItemCommand(object source, RepeaterCommandEventArgs e)
        //{
        //    if (e.CommandName == "Update")
        //    {
        //        int Carried = Convert.ToInt32(e.CommandArgument);
        //        divNewBlock.Style.Add("display", "block");
        //        Session["Cid"] = Carried.ToString();
        //        BindDivDisplay();


        //    }
        //    if (e.CommandName == "Jiesuan")
        //    {
        //        int Carried = Convert.ToInt32(e.CommandArgument);
        //        divNewBlock.Style.Add("display", "block");
        //        Session["Cid"] = Carried.ToString();
        //        Getbind();



        //    }
        //}

        protected void BtnSelect_Click(object sender, EventArgs e)
        {
            divNewBlock.Style.Add("display", "none");
            CostBLL cb = new CostBLL();
            int pageIndex = AspNetPagerTool.CurrentPageIndex;
            int pageSize = AspNetPagerTool.PageSize;
            int Rescout = 0;
            int state = Convert.ToInt32(RblSUMState.SelectedValue);
            string ReceiveDate = TxtChenDate.Text;
            string EndReceDate = Txtchengdata.Text.Trim();
            RptBindDrive.DataSource = cb.CostCarries(pageIndex, pageSize, out Rescout, state, ReceiveDate, EndReceDate);
            AspNetPagerTool.RecordCount = Rescout;
            RptBindDrive.DataBind();
        }

        protected void BtnReset_Click(object sender, EventArgs e)
        {
            RblSUMState.SelectedValue = "-1";
            TxtChenDate.Text = "";
            Txtchengdata.Text = "";
        }

        protected void AspNetPagerTool_PageChanged(object sender, EventArgs e)
        {
            BindRptList();
        }

        protected void BtnOperation_Click(object sender, EventArgs e)
        {
            //CostBLL cb = new CostBLL();
            //int carrid = Convert.ToInt32(Session["Cid"]);
            //string Zhen = @"^[0-9]\d{0,7}(\.\d{1,6})?$";
            //Regex rex = new Regex(Zhen);
            //if (rex.IsMatch(TextInsuranceCost.Text) == false || 
            //    rex.IsMatch(TextTransportCost.Text.Trim()) == false ||
            //    rex.IsMatch(TextFlie.Text.Trim()) == false ||
            //    rex.IsMatch(TextOtherCost.Text.Trim()) == false 
            //    )
            //{
            //    Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('输入的值必须是小数点类型，保留两位小数点')", true);
            //}
            //else
            //{
              //float Oilfolt = Convert.ToSingle(TextInsuranceCost.Text);
              //float Toll = Convert.ToSingle(TextTransportCost.Text);
              //float Fine = Convert.ToSingle(TextFlie.Text);
              //float Other = Convert.ToSingle(TextOtherCost.Text);
              //int result = cb.Cost(carrid, Oilfolt, Toll, Fine, Other,carrid);
              //  string name = Session["names"].ToString();
              //  string Behavor = "" + name + ": 结算承运单";
              //  int TypeId = 18;
              //  int UserID = Convert.ToInt32(Session["UserIDs"]);
              //  string Parameters = @"" + Oilfolt + "," + Toll + "," + Fine + "," + Other;
              //  string ProcName = "p_InsertCost";
              //  HttpRequest request = HttpContext.Current.Request;
              //  string IP = "192.168.0.1";
              //  int IsExcePion = 0;
                
                
              //  if (result > 0)
              //  {
              //      IsExcePion = 0;
              //      int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
              //      if (a > 0)
              //      {
              //          Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('结算成功')", true);
              //          divNewBlock.Style.Add("display", "none");
              //          BindRptList();
              //      }
                   
              //  }
              //  else
              //  {
              //      IsExcePion = 1;
              //      int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
              //      if (a > 0)
              //      {
              //          Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('结算失败')", true);
              //          divNewBlock.Style.Add("display", "none");
              //          BindRptList();
              //      }
                    
              //  }
            //}
            

        }

        //protected void BtnUpdate_Click(object sender, EventArgs e)
        //{
        //    CostBLL cb = new CostBLL();
        //    string Zhen = @"^[0-9]\d{0,7}(\.\d{1,6})?$";
        //    Regex rex = new Regex(Zhen);
        //    if (rex.IsMatch(TextInsuranceCost.Text) == false ||
        //        rex.IsMatch(TextTransportCost.Text.Trim()) == false ||
        //        rex.IsMatch(TextFlie.Text.Trim()) == false ||
        //        rex.IsMatch(TextOtherCost.Text.Trim()) == false
        //        )
        //    {
        //        Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('只能是数字或小数点类型')", true);
        //    }
        //    else
        //    {
        //        int carrid = Convert.ToInt32(Session["Cid"]);
        //        float Oilfolt = Convert.ToSingle(TextInsuranceCost.Text);
        //        float Toll = Convert.ToSingle(TextTransportCost.Text);
        //        float Fine = Convert.ToSingle(TextFlie.Text);
        //        float Other = Convert.ToSingle(TextOtherCost.Text);
        //        int result = cb.Cost(carrid, Oilfolt, Toll, Fine, Other);

        //        string name = Session["names"].ToString();
        //        string Behavor = "" + name + ": 修改成本";
        //        int TypeId = 19;
        //        int UserID = Convert.ToInt32(Session["UserIDs"]);
        //        string Parameters = @"" + Oilfolt + "," + Toll + "," + Fine + "," + Other;
        //        string ProcName = "P_UpdateCost";
        //        HttpRequest request = HttpContext.Current.Request;
        //        string IP = "192.168.0.1";
        //        int IsExcePion = 0;
                
        //        if (result > 0)
        //        {
        //            IsExcePion = 0;
        //            int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
        //            if (a > 0)
        //            {
        //                Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('修改成功')", true);
        //                divNewBlock.Style.Add("display", "none");
        //                BindRptList();
        //            }


        //        }
        //        else
        //        {
        //            IsExcePion = 1;
        //            int a = ProcBLL.InserSys(Behavor, TypeId, UserID, Parameters, ProcName, IP, IsExcePion);
        //            if (a > 0)
        //            {
        //                Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('修改失败')", true);
        //                divNewBlock.Style.Add("display", "none");
        //                BindRptList();
        //            }
        //        }
        //    }
            
        //}


        //public void BindDivDisplay()
        //{
        //    CostBLL cb = new CostBLL();
        //    int carrid = Convert.ToInt32(Session["Cid"]);
        //    SqlDataReader read = cb.BindCostRead(carrid);
        //    if (read.Read())
        //    {
        //        TextInsuranceCost.Text = read["OilCost"].ToString();
        //        TextTransportCost.Text = read["Toll"].ToString();
        //        TextFlie.Text = read["Fine"].ToString();
        //        TextOtherCost.Text = read["OtherCost"].ToString();
        //    }
            
        //}


        public void Getbind()
        {
            TextInsuranceCost.Text = "0.00";
            TextTransportCost.Text = "0.00";
            TextFlie.Text = "0.00";
            TextOtherCost.Text = "0.00";

        }
    }
}